package com.zmn.oms.third.jingdong;

import com.zmn.oms.common.constant.OrderConsts;
import com.zmn.oms.third.base.util.ProductIdUtil;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * 类描述：
 *
 * @author LiangHailong
 * @date 2019/09/07 10:25
 */
public final class JingdongMapper {

    private static final Map<String, Map<String, JingdongMapper.ZmnProductMapping>> PRODUCT_ID_MAP = new HashMap();

    /* 京东产品映射关系初始化 - 维修 */
    static {
        Map<String, ZmnProductMapping> map = new HashMap<>();
        map.put("5978594", new ZmnProductMapping(10001, 30, "", "5978594", "家用空调上门检测费 家电故障检测服务"));
        map.put("6009949", new ZmnProductMapping(10021, 30, "", "6009949", "冰箱上门检测费家电故障检测服务"));
        map.put("6022995", new ZmnProductMapping(10547, 30, "", "6022995", "洗衣机上门检测费家电故障检测服务"));
        map.put("6043921", new ZmnProductMapping(10044, 30, "", "6043921", "液晶电视机上门检测费家电故障检测服务"));
        map.put("5935491", new ZmnProductMapping(10598, 30, "", "5935491", "电热水器上门检测费家电故障检测服务"));
        map.put("5935489", new ZmnProductMapping(10752, 30, "", "5935489", "燃气热水器上门检测费家电故障检测服务"));
        map.put("6043919", new ZmnProductMapping(10073, 30, "", "6043919", "油烟机上门检测费家电故障检测服务"));
        map.put("6043899", new ZmnProductMapping(10068, 30, "", "6043899", "燃气灶上门检测费家电故障检测服务"));
        map.put("6043925", new ZmnProductMapping(10105, 30, "", "6043925", "消毒柜上门检测费家电故障检测服务"));
        map.put("6043865", new ZmnProductMapping(10094, 30, "", "6043865", "洗碗机上门检测费家电故障检测服务"));
        PRODUCT_ID_MAP.put("", map);
    }

    /**
     * 获取啄木鸟产品映射关系对象
     * @param auctionId
     * @param auctionSkuid
     * @return
     */
    public static int getZmnProductId(String auctionId, String auctionSkuid, Integer servCategId) {
       /* String auctionIdStr = Optional.ofNullable(auctionId).orElse("");
        String auctionSkuidStr = Optional.ofNullable(auctionSkuid).orElse("");

        Map<String, ZmnProductMapping> map = PRODUCT_ID_MAP.get(auctionIdStr);
        if (map == null) {
            //无法识别产品时，使用默认产品id，保证正常下单
            return getDefaultZmnProductId(servCategId);
        }

        ZmnProductMapping zmnProductMapping = map.get(auctionSkuidStr);

        if (zmnProductMapping == null) {
            //无法识别产品时，使用默认产品id，保证正常下单
            return getDefaultZmnProductId(servCategId);
        }

        return ProductIdUtil.getNewProductId(zmnProductMapping.getZmnProductId());
        */
       return ProductIdUtil.getDefaultProductId();
    }

    /**
     * 啄木鸟与京东产品映射对象
     */
    public static class ZmnProductMapping {
        private int zmnProductId;   // 啄木鸟产品ID
        private int price;  // 价格
        private String spuid; // 京东产品ID
        private String skuid; // 京东产品SKUID
        private String goodsName; // 产品名称

        public ZmnProductMapping(int zmnProductId, int price, String spuid, String skuid, String goodsName) {
            this.zmnProductId = zmnProductId;
            this.price = price;
            this.spuid = spuid;
            this.skuid = skuid;
            this.goodsName = goodsName;
        }

        public int getZmnProductId() {
            return zmnProductId;
        }

        public void setZmnProductId(int zmnProductId) {
            this.zmnProductId = zmnProductId;
        }

        public int getPrice() {
            return price;
        }

        public void setPrice(int price) {
            this.price = price;
        }

        public String getSpuid() {
            return spuid;
        }

        public void setSpuid(String spuid) {
            this.spuid = spuid;
        }

        public String getSkuid() {
            return skuid;
        }

        public void setSkuid(String skuid) {
            this.skuid = skuid;
        }

        public String getGoodsName() {
            return goodsName;
        }

        public void setGoodsName(String goodsName) {
            this.goodsName = goodsName;
        }
    }

    /**
     * 无法识别产品时，使用默认产品id，保证正常下单
     * @param servCategId
     * @return
     */
    private static int getDefaultZmnProductId(Integer servCategId) {
        return OrderConsts.CHANNEL_DISABLED_PRODUCT_ID;
    }

    /**
     * 私有构造器，禁止外部实例化
     */
    private JingdongMapper() {}
}
